<template>
  <div>
      <topnav title="立即购买"></topnav>
      <div class="fish">
          <li>
              <img :src="fish.head_img" alt="">
              <p style="text-align:center;">{{fish.nickname}}</p>
          </li>
          <li>
              <p>{{fish.introduce}}</p>
              <span>剩余条数：{{fish.stock}}条</span>
          </li>
      </div>
      <div class="detail">
          <li>
              <p>当前价格：</p>
              <span style="color:#ff6608; font-size:18px;">￥{{fish.value}}</span>
          </li>
          <li>
              <p>当前收益：</p>
              <span>{{fish.contract_revenue}}元/小时</span>
          </li>
          <li>
               <p>共计价格</p>
               <span style="color:#ff6608; font-size:18px;">￥8888</span>
                <!-- <ul class="count">
                    <li>
                        <span  @click="counts_jian">-</span>
                    </li>
                    <li>
                        <input type="text"  v-model="counts"/>
                    </li>
                    <li>
                        <span @click="counts_jia">+</span>
                    </li>
                </ul> -->
          </li>
      </div>
      <div class="footer">
          <button @click="buy">立即购买</button>
      </div>
  </div>
</template>

<script>
import topnav from "../../components/topNav"
import api from "../../axios/api"
export default {
    data(){
        return{
            counts:1,
            fish:[],
        }
    },
    mounted(){
        this.getfish()
        
    },
    methods:{
        buy(){
            let data = {
                goods_id: this.$route.query.id, 
                count:this. counts,
                user_id:localStorage.getItem("ID")
            }
            this.$post(api.placeorder,data).then(res=>{
                if(res.code == 0){
                    this.$toast("购买成功")
                }else{
                   this.$toast(res.error) 
                }
            })
        },
        getfish(){
            let data = {
                id: this.$route.query.id,   
            }
            this.$post(api.fish,data).then(res=>{
                if(res.code == 0){
                    this.fish = res.data
                }else{
                   this.$toast(res.error) 
                }
            })
        },
        counts_jian(){
            if(this.counts>1){
                this.counts--
            }
        },
        counts_jia(){
            if(this.counts<this.fish.stock){
                this.counts++
            }
        }       
        
    },
    components:{
        topnav
    }
}
</script>

<style lang="less" scoped>
.space{
    height: 8px;
    background-color: #f6f6f6;
}
.fish {
    display: flex;
    width: 90%;
    height: 90px;
    margin: 0 auto;
    margin-top: 10px;
    box-shadow: 2px 2px 10px #ccc;
    border-radius: 10px;
    color: #000;
    li{
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        margin-left: 10px;
        padding: 5px;
        width: 20%;
        font-size: 13px;
        img{
            width: 50px;
            height: 35px;
            margin: 0 auto;
        }
        p{
            width: 95%;
        }
    }
    li:nth-child(2){
        width: 70%;
        span{
            color: #ccc;
        }
    }
}
.detail{
    width: 90%;
    margin: 0 auto;
    margin-top: 10px;
    font-size: 14px;
    color: #000;
    li{
        display: flex;
        align-items: center;
        margin-top: 10px;
    }
}
.footer {
   text-align: center;
    margin-top: 100px;
    button{
        width: 80%;
        height: 50px;
        border: none;
        border-radius: 40px;
        color: #fff;
        background-color: #ff6608;
        
    }
}
.count{
    display: flex;
    font-size: 16px;
    height: 20px;
    margin-left: auto;
    align-items: center;
    text-align: center;
    background-color: #f6f6f6;
    border-radius: 5px;
    li{
        margin-top: 0px;

    }
    span{
        width: 20px;
    }
    input{
        width: 35px;
        background-color: #f6f6f6;
        border: none;
        text-align: center;
        border-left: 1px solid #fff;
        border-right: 1px solid #fff;
    }
}
</style>